/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2005                    */
/* Created on:     15.03.2012 15:00:34                          */
/*==============================================================*/


alter table article_tags
   drop constraint FK_ARTICLE__REFERENCE_ARTICLES
go

alter table article_tags
   drop constraint FK_ARTICLE__REFERENCE_TAGS
go

if exists (select 1
            from  sysobjects
           where  id = object_id('article_tags')
            and   type = 'U')
   drop table article_tags
go

if exists (select 1
            from  sysobjects
           where  id = object_id('articles')
            and   type = 'U')
   drop table articles
go

if exists (select 1
            from  sysobjects
           where  id = object_id('tags')
            and   type = 'U')
   drop table tags
go

/*==============================================================*/
/* Table: articles                                              */
/*==============================================================*/
create table articles (
   id                   int                  identity,
   title                nvarchar(200)        not null,
   content              text                 not null,
   is_published         bit                  not null default 0,
   constraint PK_ARTICLES primary key (id)
)
go

/*==============================================================*/
/* Table: tags                                                  */
/*==============================================================*/
create table tags (
   id                   nvarchar(50)         not null,
   name                 nvarchar(50)         not null,
   is_rubric            bit                  not null default 0,
   constraint PK_TAGS primary key (id)
)
go

/*==============================================================*/
/* Table: article_tags                                          */
/*==============================================================*/
create table article_tags (
   article_id           int                  null,
   tag_id               nvarchar(50)         not null,
   constraint FK_ARTICLE__REFERENCE_ARTICLES foreign key (article_id)
      references articles (id),
   constraint FK_ARTICLE__REFERENCE_TAGS foreign key (tag_id)
      references tags (id)
)
go

